import lejos.nxt.ADSensorPort;
import lejos.nxt.SensorPort;
import lejos.nxt.TouchSensor;

/**
 * @author jose
 */
public class TouchSensors {
	
	public static  final SensorPort LEFT_PORT  = SensorPort.S3;
	public static  final SensorPort RIGHT_PORT  = SensorPort.S2;
	
	public TouchSensors(){
		
	}
	/**
	 * Check if the right sensor is pressed
	 * @return true || false
	 */
	public static boolean isRightPressed()
	{
		TouchSensor	sensorRight = new TouchSensor(TouchSensors.RIGHT_PORT);
		return sensorRight.isPressed(); 
	}
	
	/**
	 * Check if the left sensor is pressed
	 * @return true || false
	 */
	public static boolean isLeftPressed()
	{
		TouchSensor	sensorLeft = new TouchSensor(TouchSensors.LEFT_PORT);
		return sensorLeft.isPressed() ; 
	}

	/**
	 * Check if any sensor is pressed
	 * @return true || false
	 */
	public static boolean isPressed()
	{
		return TouchSensors.isLeftPressed()  || TouchSensors.isRightPressed();
		
	}
	
	public void avoidDanger(){
		if(isPressed()){
			
			Moves.stop();
			Alarm.errorAlarm("The touch sensor are pressed");
/*			Moves.backward(100);
			
			try{ //I prefer use the "wait" than use a while(...) for taking two seconds 
				wait(2000);
			}catch (Exception e){
				
			}
			Moves.stop();
			
			int rotation = Eyes.getFreeAngle();	// find free area
			
			if(rotation < 0){				
				Moves.turnLeftAtSpot(rotation+100);
			}
			else{
				Moves.turnRightAtSpot(rotation+100);
			}
*/		
		}
	}

}
